﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ViewJobsApplied : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            clsJobsAppliedDAL objclsJobsAppliedDAL = new clsJobsAppliedDAL();
            List<clsJobApplied> objclsJobAppliedList = new List<clsJobApplied>();
            if (Session["UserId"] != null && Session["EmployerId"] != null)
            {
                objclsJobAppliedList = objclsJobsAppliedDAL.GetAppliedJobByEmployerId(Convert.ToInt32(Session["EmployerId"].ToString()), Convert.ToInt32(Session["UserId"].ToString()));
                grdViewJobsApplied.DataSource = objclsJobAppliedList;
                grdViewJobsApplied.DataBind();
            }
            else
            {
                Response.Redirect("EmployerLogin.aspx");
            }
        }
    }
    protected void btnStatusChange_Click(object sender, EventArgs e)
    {
        try
        {
            if (hfJobAppliedId.Value != "")
            {
                clsJobsAppliedDAL objclsJobsAppliedDAL = new clsJobsAppliedDAL();
                IN_TB_JOB_APPLIED objIN_TB_JOB_APPLIED = new IN_TB_JOB_APPLIED();
                objIN_TB_JOB_APPLIED = objclsJobsAppliedDAL.GetJobsAppliedById(Convert.ToInt32(hfJobAppliedId.Value.ToString()));
                objIN_TB_JOB_APPLIED.STATUS = Convert.ToInt32(ddlStatus.SelectedValue);
                objIN_TB_JOB_APPLIED.EMPLOYER_COMMENT = txtComment.Text;
                objclsJobsAppliedDAL.SaveJobsApplied(objIN_TB_JOB_APPLIED);
                List<clsJobApplied> objclsJobAppliedList = new List<clsJobApplied>();
                if (Session["UserId"] != null && Session["EmployerId"] != null)
                {
                    objclsJobAppliedList = objclsJobsAppliedDAL.GetAppliedJobByEmployerId(Convert.ToInt32(Session["EmployerId"].ToString()), Convert.ToInt32(Session["UserId"].ToString()));
                    grdViewJobsApplied.DataSource = objclsJobAppliedList;
                    grdViewJobsApplied.DataBind();
                    hfJobAppliedId.Value = "";
                    ddlStatus.SelectedIndex = 0;
                    txtComment.Text = "";
                }
                else
                {
                    Response.Redirect("EmployerLogin.aspx");
                }
            }
            pnlStatusChange.Visible = false;
        }
        catch (Exception)
        {
            throw;
        }
    }
    protected void grdViewJobsApplied_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "ChangeStatus")
            {
                pnlStatusChange.Visible = true;
                hfJobAppliedId.Value = Convert.ToString(e.CommandArgument);
            }
        }
        catch (Exception)
        {
            throw;
        }
    }
    protected void grdViewJobsApplied_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //Getting Status
                string Status = Convert.ToString(e.Row.Cells[12].Text);
                if (Status == "1")
                    e.Row.Cells[12].Text = "Not Seen";
                if (Status == "2")
                    e.Row.Cells[12].Text = "Seen";
                if (Status == "3")
                    e.Row.Cells[12].Text = "On Hold";
                if (Status == "4")
                    e.Row.Cells[12].Text = "Selected";
                if (Status == "5")
                    e.Row.Cells[12].Text = "Rejected";

                // Geting Functional Area
                int Functional_AreaId = Convert.ToInt32(e.Row.Cells[9].Text);
                clsFunctionalAreaDAL objclsFunctionalAreaDAL = new clsFunctionalAreaDAL();
                IN_TB_FUNCTIONAL_AREA objIN_TB_FUNCTIONAL_AREA = new IN_TB_FUNCTIONAL_AREA();
                objIN_TB_FUNCTIONAL_AREA = objclsFunctionalAreaDAL.GetAllFunctionalAreaById(Functional_AreaId);
                e.Row.Cells[9].Text = objIN_TB_FUNCTIONAL_AREA.FUNCTIONAL_AREA;
            }
        }
        catch (Exception)
        {
            throw;
        }
    }
}